package com.ljfiction.book.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ljfiction.book.Baner.FistHom;
import com.ljfiction.book.MyView.RoundAngleImageView;
import com.ljfiction.book.R;
import com.ljfiction.book.tools.ScreenUtils;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2017/7/7.
 */

public class HotBookAdapter extends BaseAdapter {
    private Context context;
    private List<FistHom.DataBean.HostXiaoBianRecommendBean> listItems;
    private boolean isDel=false;

    public boolean isDel() {
        return isDel;
    }

    public void setIsDel(boolean isDel) {
        this.isDel = isDel;
    }

    public final class ListItemView {
        @ViewInject(R.id.hotbook_imageview)
        public RoundAngleImageView bookimage;
        @ViewInject(R.id.hotbook_writername)
        public TextView writerName;
        @ViewInject(R.id.hotbook_bookname)
        public TextView bookname;
    }

    public HotBookAdapter(Context context, List<FistHom.DataBean.HostXiaoBianRecommendBean> listItems) {
        this.context = context;

        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            listItemView = new ListItemView();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.gridview_hotbook, null);
            x.view().inject(listItemView,convertView);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }
        Glide.with(context).load(listItems.get(position).getBookImage()).override(ScreenUtils.getNum(context,107),ScreenUtils.getNum(context,141)).into(listItemView.bookimage);
        listItemView.writerName.setText(listItems.get(position).getWriterName());
        listItemView.bookname.setText(listItems.get(position).getBookName());

        return convertView;
    }

    public Listener getListener() {
        return listener;
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }

    private Listener listener;
    public interface Listener {
        public void click(FistHom.DataBean.HostXiaoBianRecommendBean Book);
    }
}
